﻿/*include:js\overDiv*/
//界面居中弹出层	<div body="true" floatcenter="{}" id="XXX" style="display:none"></div>
//fastCSharp.FloatCenters.XXX.Show();
(function(){
var FloatCenter=function()
	{
	this.GetArgument(arguments[0],{Id:null,IsFixed:0,IsEsc:1,Timeout:200,SkinView:null,ZIndex:0,AutoClass:null});
	this.KeyDownFunction=fastCSharp.ThisEvent(this,this.KeyDown);
	if(this.SkinView)	this.Skin=fastCSharp.Skins[this.Id]||new fastCSharp.Functions.Skin({Id:this.Id});
	if(fastCSharp.IsFixed)
		{
		if(!this.AutoClass)	this.$Id(this.Id).Css('position','fixed').Css('top,left','50%').Css('transform','translateX(-50%) translateY(-50%)');
		}
	else	{
		this.$Id(this.Id).Css('position','absolute');
		this.ShowFunction=fastCSharp.ThisFunction(this,this.Show);
		this.Hide();
		}
	};
(fastCSharp.Functions.FloatCenter=FloatCenter).Inherit(fastCSharp.BaseFunction,{
Show:function()
	{
	var Element=this.$Id(this.Id);
	if(fastCSharp.IsFixed)
		{
		fastCSharp.OverDiv.Show(this.Id,this.ZIndex||!this.AutoClass?fastCSharp.ZIndex+this.ZIndex:0);
		Element.Css('zIndex',fastCSharp.ZIndex+this.ZIndex);
		if(this.AutoClass)
			{
			if(this.Skin)	this.Skin.SetHtml(this.SkinView);
			Element.Class(this.AutoClass);
			}
		else	{
			if(this.Skin)	this.Skin.Show(this.SkinView);
			else Element.Display(1);
			}
		}
	else	{
		fastCSharp.OverDiv.Show();
		if(this.Skin)	this.Skin.Show(this.SkinView);
		else	Element.Display(1);
		var Left=(fastCSharp.$ScrollLeft()+(this.$Width()-Element.Width())/2),Top=(fastCSharp.$ScrollTop()+(this.$Height()-Element.Height())/2);
		Element.Css('zIndex',fastCSharp.ZIndex+this.ZIndex).ToXY(Left<0?0:Left,Top<0?0:Top);
		if(this.IsFixed)
			{
			if(this.ShowInterval)	clearTimeout(this.ShowInterval);
			this.ShowInterval=setTimeout(this.ShowFunction,this.Timeout);
			}
		}
	if(this.IsEsc)	fastCSharp.$(document.body).AddEvent('keydown',this.KeyDownFunction);
	},
Hide:function()
	{
	fastCSharp.$(document.body).DeleteEvent('keypress',this.KeyDownFunction);
	var Element=this.$Id(this.Id);
	if(fastCSharp.IsFixed)
		{
		if(this.AutoClass)
			{
			Element.Class(this.AutoClass,1);
			Element.Css('zIndex',-100);
			}
		else	Element.Display(0);
		fastCSharp.OverDiv.Hide(this.Id);
		}
	else	{
		if(this.ShowInterval)	clearTimeout(this.ShowInterval);
		this.ShowInterval=null;
		Element.Display(0);
		fastCSharp.OverDiv.Hide();
		}
	},
KeyDown:function(Event)
	{
	if(Event.KeyCode==27)
		{
		var Element=Event.ElementName('floatcenter');
		if(Element&&Element.Id()==this.Id)	this.Hide();
		}
	}
		});
fastCSharp.GetFloatCenters=function()
	{
	if(!this.FloatCenters)	this.OnLoadedHash.Add(this.ThisFunction(this,this.GetFloatCenters));
	this.FloatCenters={};
	for(var Childs=this.$('@floatcenter').GetElements(),Index=Childs.length;--Index>=0;)
		{
		var Element=Childs[Index],Parameter=this.$Attribute(Element,'floatcenter');
		(Parameter=Parameter?eval('('+Parameter+')'):{}).Id=Element.id;
		this.FloatCenters[Element.id]=new this.Functions.FloatCenter(Parameter);
		}
	};
fastCSharp.OnLoad(fastCSharp.GetFloatCenters,fastCSharp,1);
})();